<?php
require_once("../../config.inc.php");
require_once "../../app/_inc/sdao/StructuredDataAccessObject.php";
if(isset($_REQUEST['tipo']) and $_REQUEST['tipo'] != 'DB') {
	if(strtolower($aMetaConPar["dbcType"]) != "mysqli"){
		die("Funzione prevista solo per MySQLi");
	}
	echo "<pre>Converti utf8_general_ci\n";
	$SDAO = new SDAO($aMetaConPar);
} else {
	if(strtolower($aDataConPar["dbcType"]) != "mysqli"){
		die("Funzione prevista solo per MySQLi");
	}
	echo "<pre>Converti utf8_general_ci\n";
	$SDAO = new SDAO($aDataConPar);
}

$sql = "ALTER DATABASE  `".$aMetaConPar['dbName'].
	"` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
$SDAO->query($sql,'al');
echo "eseguito : $sql\n";

$sql = "SHOW TABLES";
$SDAO->query($sql,'ListaTabelle');

while($row = $SDAO->fetch('ListaTabelle')) {
	$aX = array_values($row);
	$sql = "ALTER TABLE ".$aX[0].
		" CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
	$SDAO->exec($sql);
	echo "eseguito : $sql\n";
	$sql = "SHOW FULL COLUMNS FROM ".$aX[0];
	$SDAO->query($sql,'listaCampi');
	while($row2 = $SDAO->fetch('listaCampi')) {
		if (!empty($row2['Collation']) and $row2['Collation'] != 'utf8_general_ci') {
			$sqlAC = "ALTER TABLE ".$aX[0]." CHANGE ".$row2['Field']." ".$row2['Field']." ".$row2['Type'].
			" CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '".addslashes($row2['Default'])."'";
			$SDAO->exec($sqlAC);
			echo "eseguito : $sqlAC\n";
		}
	}
}

print "*** Esecuzione terminata ***</pre>";
?>  
